//
//  MineSettingViewController.m
//  Peso Guide
//
//  Created by macbook on 2025/6/12.
//

#import "MineSettingViewController.h"
#import "MineSettingHeaderView.h"
#import "MineSettingViewCell.h"
#import "CustomWebViewController.h"
#import "ProductDetailViewController.h"
#import "MineCancelAccountVC.h"
#import "QuiteAlertView.h"

@interface MineSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) MineSettingHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation MineSettingViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navView.backgroundColor = ColorHex(@"#1A7A35");
    self.titleLabel.text = [Lang set:@"Settings"];
    self.backColor = ColorHex(@"#1A7A35");
    
    [self.view addSubview:self.tableView];
    
    self.dataArray = [NSMutableArray arrayWithArray:@[@{@"name":[Lang set:@"Account cancelation"],@"type":@"1"},@{@"name":[Lang set:@"Exit"],@"type":@"2"}]];
    
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate&UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *MineSettingViewCellIdentifier = [NSString stringWithFormat:@"MineSettingViewCellIdentifier%ld",(long)indexPath.row];
    MineSettingViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MineSettingViewCellIdentifier];
    if (!cell) {
        cell = [[MineSettingViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MineSettingViewCellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (self.dataArray.count > 0) {
        cell.dataDic = [self.dataArray safeObjectAtIndex:indexPath.row];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (_headerView == nil) {
        _headerView = [[MineSettingHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 246)];
    }
    return _headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 246;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dataDic = [self.dataArray safeObjectAtIndex:indexPath.row];
    NSString *type = [NSString stringWithFormat:@"%@",[dataDic safeObjectForKey:@"type"]];

    if ([type integerValue] == 1) {
        MineCancelAccountVC *vc = [[MineCancelAccountVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    if ([type integerValue] == 2) {
        QuiteAlertView *alertView = [[QuiteAlertView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
        [self.view addSubview:alertView];
    }
}

#pragma mark - lazy load
- (BaseTableView *)tableView {
    if (!_tableView) {
        _tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, kStarBarHeight, KScreenWidth, KScreenHeight-kStarBarHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = ColorHex(@"#FFFFFF");
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
